//
// Created by Administrator on 25-6-30.
//
#include "DAC.h"

void DAC_SetStatus(struct DACOBJ *obj, uint8_t status) {
    if (status) {
        HAL_DAC_Start(obj->hdac, obj->Channel);
    }else {
        HAL_DAC_Stop(obj->hdac, obj->Channel);
    }
}

void DAC_OutArray(struct DACOBJ *obj, uint16_t *arr, uint32_t len, uint32_t time) {
    for (int i = 0; i < len; i++) {
        HAL_DAC_SetValue(obj->hdac, obj->Channel, DAC_ALIGN_12B_R, arr[i]);
        HAL_Delay(time);
    }

}

void DAC_OutArray_DMA(struct DACOBJ *obj, TIM_HandleTypeDef *TIMx, uint16_t *arr, uint32_t len) {
    HAL_TIM_Base_Start(TIMx);
    HAL_DAC_Start_DMA(obj->hdac, obj->Channel, arr, len, DAC_ALIGN_12B_R);
}

void DAC_OutV(struct DACOBJ *obj, uint16_t v, uint32_t time) {
    HAL_DAC_SetValue(obj->hdac, obj->Channel, DAC_ALIGN_12B_R, v);
}
